<?php

/*
	There are some generic properties within google whereby all charts can use them
	Here is the list.
	Lets start with bar chart first else the list will get bigger and bigger
		- Chart Title (chtt, chts)
		- Chart Legent Text and Style (chdl, chdlp, chdls)
		- Chart Margins (chma)
		- Axis Styles and Labels
			* Visibilbe Axes (chxt)
			* Axis Range (chxr)
			* Custom Axis Labels (chxl)
			* Axis Label Positions (chxp)
			* Axis Label Styles (chxs)
			* Axis Tick Marks (chxtc)
		- Background Fills (chf)
			* Solid Fills (chf)
			* Gradient Fills (chf)
			* Striped Fills (chf)
		- Grid Lines (chg)
		- Dynamic Markers (chem)
		- Shape Markers (chm)
		- Text and Data Value Markers (chm)
		- Range Markers (chm=r|R)
		- Candlestick Markers (chm=F)
		- Line Markers (chm=D)
		- Data functions (chfd)
*/

Class GenericProperty()
{
	// Setup Some public values
	public $title 			= '';	// chtt=Hello
	public $title_style 	= '';	// chts=FF0000,12			- Color, Font Size

	public $legend_label	= '';	// chdl=label_1|label_2 	- Label Names, | is the delimiter
	public $legend_pos		= '';	// chdlp=<opt_position>,<opt_label_order>
	public $legend_color	= '';	// chdls=FF0000,12			- Color,Font Size
	/*
		opt_position
			b - Legend at the bottom of the chart, legend entries in a horizontal row.
			bv - Legend at the bottom of the chart, legend entries in a vertical column.
			t - Legend at the top of the chart, legend entries in a horizontal row.
			tv - Legend at the top of the chart, legend entries in a vertical column.
			r - [Default] Legend to the right of the chart, legend entries in a vertical column.
			l - Legend to the left of the chart, legend entries in a vertical column.

		opt_label_order
			l - [Default for vertical legends] Display labels in the order given to chdl.
			r - Display labels in the reverse order as given to chdl. This is useful in stacked bar charts to show the legend
				in the same order as the bars appear.
			a - [Default for horizontal legends] Automatic ordering: roughly means sorting by length, shortest first, as measured in 10 pixel blocks. When two elements are the same length (divided into 10 pixel blocks), the one listed first will appear first.
			0,1,2... - Custom label order. This is a list of zero-based label indexes from chdl, separated by commas.
	*/

	public $margin			= '';	// chma=<left_margin>,<right_margine>,<top_margin>,<bottom_margin>|<opt_legend_width>,<opt_legend_height>

	// The following only applicable to line, bar, Google-O-meter, Radar, Scatter
	public $axis_visible	= '';	// chxt=x,t,y,r	
							// x - bottom x-axis, t - top x-axis
							// y - left y-axis, r - right y-axis
	public $axis_range		= '';	// chxr = <axis_index>,<start_val>,<end_val>,<opt_step>, | will be the delimiter
							// axis_index base on chxt, eg chxt=x,t,y,r => axis_index of y = 2
	public $axis_label		= '';	// chxl=<axis_index>:|<label_1>|...|<label_n>
	public $axis_label_pos	= '';	// chxp=<axis_1_index>,<label_1_position>,...,<label_n_position>
	// public $axis_style		= '';	// Lets not perform this style at the moment, too messy <TODO>
	public $axis_tick		= '';	// <axis_index_1>,<tick_length_1>,...,<tick_length_n>, | will be the delimiter if multiple ticks are used

	function __construct()
	{
		// Define some default values
		$this->title			= 'chtt=My+New+Chart';
		$this->title_style		= 'chts=FF0000,12';

		$this->legend_label		= 'chdl=';
		$this->legend_pos		= 'chdlp=';
		$this->legend_style		= 'chdls=';

		$this->margin			= '';

		$this->axis_visible		= '';
		$this->axis_range		= '';
		$this->axis_label		= '';
		$this->axis_label_pos	= '';
		$this->axis_tick		= '';
	}

	function set_title($new_title);
	{
		return $this->title = 'chtt='.str_replace(' ', '+', $new_title);
	}

	function set_title_style($title_color, $title_font_size)
	{
		return $this->title_style = 'chts='.$title_color.','.$title_font_size;	
	}

	function set_legend_label($labels)
	{
		if (is_array($labels))
		{
			foreach ($labels as $label)
			{
				$this->legend_label.=''.$label.'|';
			}
			rtrim($this->legend_label, '|');
		}
		else
		{
			$this->legend_label = 'chdl='.$labels;
		}

		return $this->legend_label;
	}

	/**************************************************
		legend_pos definition
			legend bottom horizontal	= b
			legend bottom vertical		= bv
			legend top horizontal		= t
			legend top vertical			= tv
			legend right 				= r
			legend left					= l 
	*/
	function set_legend_pos($legend_pos, $legend_order)
	{
		switch ($legend_pos)
		{
			case 'b':
			case 'bottom_horizontal':
				$this->legend_pos = 'chdlp=b';
				break;
			case 'bv':
			case 'bottom_vertical':
				$this->legend_pos = 'chdlp=bv';
				break;
			case 't':
			case 'top_horizontal':
				$this->legend_pos = 'chdlp=t';
				break;
			case 'tv':
			case 'top_vertical':
				$this->legend_pos = 'chdlp=tv';
				break;
			case 'l':
			case 'left':
				$this->legend_pos = 'chdlp=l';
				break;
			case 'r':
			case 'right':
			default:
				$this->legend_pos = 'chdlp=r';
				break;
		}
	}

	function set_legend_style($legend_color, $legend_style)
	{
		return $this->legend_style = 'chdls='.$legend_color.','.$legend_style;
	}
}
?>
